function simulateClickSelect(element) {
    const event = new MouseEvent('click', {
        bubbles: true,
        cancelable: true,
        view: window
    });
    if(element!=null) element.dispatchEvent(event);
}
async function clickElement(element) {
    return new Promise((resolve, reject) => {
        element.click();
        resolve();
    });
}


function findSelectorEqText(includeSelector,text){
    const includeElement = document.querySelectorAll(Selector);
    if (!includeElement) return null;
    for (let j = 0; j < includeElement.length; j++) {
        if (includeElement[j].textContent.trim() === text) {
            return p_elements[j];
        }
    }
    return null;
}

function findSelectorHasTextInArea(documentOrShadowRootOrOther,Selector,text){
    const includeElement = documentOrShadowRootOrOther.querySelectorAll(Selector);
    if (!includeElement) return null;
    for (let j = 0; j < includeElement.length; j++) {
        if (includeElement[j].textContent.trim() === text) {
            return includeElement[j];
        }
    }
    return null;
}

function findSelectorHasAttr(documentOrShadowRootOrOther,Selector,attrStr){
    const includeElement = documentOrShadowRootOrOther.querySelectorAll(includeSelector);
    if (!includeElement) return null;
    for (let j = 0; j < includeElement.length; j++) {
        if (includeElement[j].hasAttr(attrStr)) {
            return includeElement[j];
        }
    }
    return null;
}

function findParentChildText(documentOrShadowRootOrOther,parentSelector,childSelector,text) {
    const p_elements = documentOrShadowRootOrOther.querySelectorAll(parentSelector);
    if (!p_elements) return null;
    for (let i = 0; i < p_elements.length; i++) {
        const includeElement = p_elements[i].querySelectorAll(childSelector);
        if (!includeElement) return null;
        if(findSelectorHasTextInArea(p_elements[i],childSelector,text)!=null){
            return p_elements[i];
        }
    }
    return null;
}
function echo(elements,ors=true){
    if(true) {
        s = "";
        for (let i = 0; i < elements.length; i++) {
            s = s + elements[i].outerHTML + '\n====================================\n';
        }
        console.log(s);
    }else{
        console.log(elements.outerHTML);
    }

}

